<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User History</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f0f0f0;
        }

        h1 {
            text-align: center;
            padding: 20px;
            background-color: #3498db;
            color: #fff;
            margin: 0;
        }

        #history-list {
            max-width: 600px;
            margin: 20px auto;
            padding: 10px;
            background-color: #fff;
            border: 1px solid #ddd;
            box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
        }
    </style>
</head>
<body>
    <h1>User History</h1>
    <div id="history-list">
        <!-- 用户浏览历史将在这里展示 -->
    </div>
    <script>
        // 模拟历史记录数据
        var history = [
            {
                id: 1,
                user_id: 101,
                good_id: 201,
                type: 'view',
                createTime: '2023-08-22T10:00:00'
            },
            // ... 其他历史记录
        ];

        // 获取指定用户的浏览历史
        function getUserHistory(user_id) {
            return history.filter(record => record.user_id === user_id);
        }

        // 更新页面中的浏览历史列表
        function updateHistoryList(user_id) {
            var historyList = document.getElementById('history-list');
            var userHistory = getUserHistory(user_id);

            historyList.innerHTML = ''; // 清空列表

            if (userHistory.length === 0) {
                historyList.innerHTML = '<p>No history available.</p>';
                return;
            }

            var listHtml = '<ul>';
            userHistory.forEach(record => {
                listHtml += '<li>';
                listHtml += `Product ID: ${record.good_id}, Type: ${record.type}, Created At: ${record.createTime}`;
                listHtml += '</li>';
            });
            listHtml += '</ul>';

            historyList.innerHTML = listHtml;
        }

        // 在页面加载时更新用户101的浏览历史列表
        window.onload = function() {
            updateHistoryList(101);
        };
    </script>
</body>
</html>
